# to run this compose project, first run: npm run build or npm run build:watch (with hot-reload)
services:
  notifications:
    container_name: 'boticord-notifications-dev'
    hostname: 'notifications-service'
    image: node:18
    networks:
      - boticord-network-dev
    restart: unless-stopped
    command: "bash -c 'apt-get update && node ./dist/apps/notifications/wrapper/main.js'"
    working_dir: /app
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.ws-ws.entrypoints=ws"
      - "traefik.http.routers.ws-ws.rule=Host(`gateway.localhost`)"
      - "traefik.http.routers.ws-ws.service=ws-ws"
    depends_on:
      - postgres
      - nats
      - redis
    environment:
      - BOTICORD_SERVICE=ws-dev
    env_file:
      - .env-dev
    volumes:
      - .:/app

  resources:
    container_name: 'boticord-resources-dev'
    hostname: 'resources-service'
    image: node:16.16.0-slim
    networks:
      - boticord-network-dev
    restart: unless-stopped
    command: "node ./dist/apps/resources/src/main.js"
    working_dir: /app
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.resources.entrypoints=http"
      - "traefik.http.routers.resources.rule=Host(`api.localhost`) && PathPrefix(`/servers`) && PathPrefix(`/bots`) && PathPrefix(`/resources`) && PathPrefix(`/stats`)"
      - "traefik.http.services.resources.loadbalancer.server.port=3000"
      - "traefik.http.middlewares.resources-strip.stripprefix.prefixes=/servers,/bots"
      - "traefik.http.routers.resources.middlewares=users-strip@docker"
    depends_on:
      - postgres
      - nats
      - redis
      - bot
    environment:
      - BOTICORD_SERVICE=resources-dev
    env_file:
      - .env-dev
    volumes:
      - .:/app

  search:
    container_name: 'boticord-search-dev'
    hostname: 'search-service'
    image: node:16.16.0-slim
    networks:
      - boticord-network-dev
    restart: unless-stopped
    command: "node ./dist/apps/search/src/main.js"
    working_dir: /app
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.search-key.entrypoints=http"
      - "traefik.http.routers.search-key.rule=Host(`api.localhost`) && PathPrefix(`/search-key`)"
      - "traefik.http.services.search-key.loadbalancer.server.port=3000"
      - "traefik.http.middlewares.search-key-strip.stripprefix.prefixes=/search-key"
      - "traefik.http.routers.search-key.middlewares=users-strip@docker"
    depends_on:
      - meili
    environment:
      - BOTICORD_SERVICE=search-dev
    env_file:
      - .env-dev
    volumes:
      - .:/app

  bot:
    container_name: 'boticord-bot-dev'
    hostname: 'bot-service'
    image: node:16.16.0-slim
    networks:
      - boticord-network-dev
    restart: unless-stopped
    command: "node ./dist/apps/bot/src/main.js"
    working_dir: /app
    depends_on:
      - postgres
      - nats
      - redis
    environment:
      - BOTICORD_SERVICE=bot-dev
    env_file:
      - .env-dev
    volumes:
      - .:/app

  cdn:
    container_name: 'boticord-cdn-dev'
    hostname: 'cdn-service'
    image: node:16.16.0-slim
    networks:
      - boticord-network-dev
    restart: unless-stopped
    command: "node ./dist/apps/cdn/src/main.js"
    working_dir: /app
    depends_on:
      - postgres
      - nats
      - redis
    environment:
      - BOTICORD_SERVICE=cdn-dev
    env_file:
      - .env-dev
    volumes:
      - .:/app

  users:
    container_name: 'boticord-users-dev'
    hostname: 'users-service'
    image: node:16.16.0-slim
    networks:
      - boticord-network-dev
    restart: unless-stopped
    command: "node ./dist/apps/users/src/main.js"
    working_dir: /app
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.users.entrypoints=http"
      - "traefik.http.routers.users.rule=Host(`api.localhost`) && PathPrefix(`/users`)"
      - "traefik.http.services.users.loadbalancer.server.port=3000"
      - "traefik.http.middlewares.users-strip.stripprefix.prefixes=/users"
      - "traefik.http.routers.users.middlewares=users-strip@docker"
    depends_on:
      - postgres
      - nats
      - redis
    environment:
      - BOTICORD_SERVICE=users-dev
    env_file:
      - .env-dev
    volumes:
      - .:/app

  traefik:
    container_name: 'boticord-traefik'
    image: traefik
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.yml:/etc/traefik/traefik.yml
    restart: on-failure
    networks:
      - boticord-network-dev
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik-dash.entrypoints=http"
      - "traefik.http.routers.traefik-dash.rule=Host(`traefik.localhost`)"
      - "traefik.http.services.traefik-dash.loadbalancer.server.port=8080"
    ports:
      - 127.0.0.1:80:80
      - 127.0.0.1:8940:8080

  nats:
    container_name: 'boticord-nats-dev'
    hostname: 'nats'
    networks:
      - boticord-network-dev
    restart: unless-stopped
    image: nats

  meili:
    container_name: 'boticord-meili-dev'
    hostname: 'meili'
    networks:
      - boticord-network-dev
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.meili.entrypoints=http"
      - "traefik.http.middlewares.meili-strip.stripprefix.prefixes=/search"
      - "traefik.http.routers.meili.middlewares=meili-strip@docker"
      - "traefik.http.routers.meili.rule=Host(`api.localhost`) && PathPrefix(`/search`)"
      - "traefik.http.services.meili.loadbalancer.server.port=7700"
    image: 'getmeili/meilisearch:v1.1.1'
    volumes:
      - meili:/meili_data
    env_file:
      - ./.env-dev

  adminer:
    container_name: 'boticord-adminer-dev'
    hostname: 'adminer'
    networks:
      - boticord-network-dev
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.adminer.entrypoints=http"
      - "traefik.http.routers.adminer.rule=Host(`adminer.localhost`)"
      - "traefik.http.services.adminer.loadbalancer.server.port=8080"
    image: adminer

  redis:
    container_name: 'boticord-redis-dev'
    hostname: 'redis'
    networks:
      - boticord-network-dev
    restart: unless-stopped
    image: redis
    command: --save 60 10
    volumes:
      - redis:/data

  postgres:
    container_name: 'boticord-postgres-dev'
    hostname: 'postgres'
    networks:
      - boticord-network-dev
    restart: unless-stopped
    image: postgres
    env_file:
      - ./.env-dev
    volumes:
      - postgres:/var/lib/postgresql/data

volumes:
  postgres:
  meili:
  redis:

networks:
  boticord-network-dev:
